<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'bookdesc.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
	body {
		font-size: 10pt;
		background: rgb(254,238,189);
	}
	div {
		margin:20px;
		border: solid 2px gray;
		width: 150px;
		height: 150px;
		text-align: center;
	}
	li {
		margin: 10px;
	}
</style>
	  <script type="text/javascript" src="/adminjsps/js/jquery-3.2.1.min.js"></script>
  </head>
  
  <body>
  <div class="div1">
    <%--<img src="/adminjsps/admin/book_img/20029394-1_l.jpg" border="0"/>--%>
  </div>
  <div style="margin:20px;">
  	图书名称：<input type="text" name="bname" id="bname" value=""/><br/>
  	图书单价：<input type="text" name="price" id="price" value=""/><br/>
  	图书作者：<input type="text" name="author" id="author" value=""/><br/>
  	图书分类：<select style="width: 150px; height: 20px;" id="cate" name="cid">
     		<%--<option value="">JavaSE</option>--%>
    		<%--<option value="">JavaEE</option>--%>
			<%--<option value="">JavaScript</option>--%>
			<%--<option value="">Hibernate</option>--%>
			<%--<option value="">Struts</option>--%>
			<%--<option value="" selected='selected'>Spring</option>--%>
    	</select><br/>
  	<input type="button" name="" class="del" value="删除"/>
  	<input type="button" name="" class="change" value="修改"/>
	  <span id="span"></span>
  </div>
  <script>
	  window.onload=function () {
		  $.ajax({
			  url:"/bookandcate",
			  type:"get",
			  success:function (re) {
				var i;
				for (i = 0; i < re.category.length; i++) {
					$("<option>"+re.category[i].cname+"</option>").appendTo("select")
				}
				$("#bname").val(re.data.bname);
				$("#price").val(re.data.price);
				$("#author").val(re.data.author);
				$("#cate").val(re.data.cname);
				$("<img src="+re.data.image+" border=\"0\"/>")
			  }
		  })
	  };
	  $(".del").click(function () {
		  $.ajax({
			  url:"/delbook",
			  get:"get",
			  success:function (re) {
				  // alert(re.msg)
				  $("#span").html(re.msg)
			  }
		  })
	  });
    $(".change").click(function () {
        var bname = $("#bname").val();
        var price = $("#price").val();
        var author = $("#author").val();
        var cate = $("#cate").val();
        $.ajax({
            url:"/changebook",
            type:"get",
            data:{
                bname:bname,
                price:price,
                author:author,
                cate:cate
            },
            success:function (re) {
				// alert(re.msg);
				$("#span").html(re.msg)
            }
        })
    })
  </script>
  </body>
</html>
